package com.wutuo.roster.provider.dao;

import com.wutuo.roster.provider.domain.Roster;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author lvh
 * @version 1.0
 */

public class BaseRosterSqlProvider implements java.io.Serializable {

    public String insertSelective(Roster record) {

        BEGIN();
        INSERT_INTO("roster");
        insertKey(record);
        return SQL();
    }

    public void insertKey(Roster record) {

        if (record.getTeacherId() != null) {
            VALUES("teacher_id", "#{teacherId,jdbcType=BIGINT}");
        }
        if (record.getCmInstitutionId() != null) {
            VALUES("cm_institution_id", "#{cmInstitutionId,jdbcType=BIGINT}");
        }
        if (record.getCreateBy() != null) {
            VALUES("create_by", "#{createBy,jdbcType=BIGINT}");
        }
        if (record.getCreateDate() != null) {
            VALUES("create_date", "#{createDate,jdbcType=DATE}");
        }
        if (record.getUpdateBy() != null) {
            VALUES("update_by", "#{updateBy,jdbcType=BIGINT}");
        }
        if (record.getUpdateDate() != null) {
            VALUES("update_date", "#{updateDate,jdbcType=DATE}");
        }
        if (record.getRemarks() != null) {
            VALUES("remarks", "#{remarks,jdbcType=VARCHAR}");
        }
        if (record.getDelFlag() != null) {
            VALUES("del_flag", "#{delFlag,jdbcType=VARCHAR}");
        }
        if (record.getName() != null) {
            VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        if (record.getPhoto() != null) {
            VALUES("photo", "#{photo,jdbcType=VARCHAR}");
        }
        if (record.getSex() != null) {
            VALUES("sex", "#{sex,jdbcType=VARCHAR}");
        }
        if (record.getTgZt() != null) {
            VALUES("tg_zt", "#{tgZt,jdbcType=VARCHAR}");
        }
        if (record.getYear() != null) {
            VALUES("year", "#{year,jdbcType=BIGINT}");
        }
        if (record.getGrade() != null) {
            VALUES("grade", "#{grade,jdbcType=BIGINT}");
        }
    }

    public String updateByPrimaryKeySelective(Roster record) {

        BEGIN();
        UPDATE("roster");
        updateKey(record);
        WHERE("id = #{id,jdbcType=BIGINT}");
        return SQL();
    }

    public void updateKey(Roster record) {

        if (record.getId() != null) {
            SET("id = #{id,jdbcType=BIGINT}");
        }
        if (record.getTeacherId() != null) {
            SET("teacher_id = #{teacherId,jdbcType=BIGINT}");
        }
        if (record.getCmInstitutionId() != null) {
            SET("cm_institution_id = #{cmInstitutionId,jdbcType=BIGINT}");
        }
        if (record.getCreateBy() != null) {
            SET("create_by = #{createBy,jdbcType=BIGINT}");
        }
        if (record.getCreateDate() != null) {
            SET("create_date = #{createDate,jdbcType=DATE}");
        }
        if (record.getUpdateBy() != null) {
            SET("update_by = #{updateBy,jdbcType=BIGINT}");
        }
        if (record.getUpdateDate() != null) {
            SET("update_date = #{updateDate,jdbcType=DATE}");
        }
        if (record.getRemarks() != null) {
            SET("remarks = #{remarks,jdbcType=VARCHAR}");
        }
        if (record.getDelFlag() != null) {
            SET("del_flag = #{delFlag,jdbcType=VARCHAR}");
        }
        if (record.getName() != null) {
            SET("name = #{name,jdbcType=VARCHAR}");
        }
        if (record.getPhoto() != null) {
            SET("photo = #{photo,jdbcType=VARCHAR}");
        }
        if (record.getSex() != null) {
            SET("sex = #{sex,jdbcType=VARCHAR}");
        }
        if (record.getTgZt() != null) {
            SET("tg_zt = #{tgZt,jdbcType=VARCHAR}");
        }
        if (record.getYear() != null) {
            SET("year = #{year,jdbcType=BIGINT}");
        }
        if (record.getGrade() != null) {
            SET("grade = #{grade,jdbcType=BIGINT}");
        }
    }
}